package com.gitee.wsl.common.ui.draw.style

import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Fill

/**
 * Provides styling for areas.
 *
 * @param brush the color/fill to be applied to the area
 * @param alpha opacity to be applied to the brush from 0.0f to 1.0f representing fully transparent to
 * fully opaque respectively
 * @param colorFilter [ColorFilter] to apply to the brush when drawn into the destination
 * @param blendMode the [BlendMode] blending algorithm to apply to the brush
 **/
data class AreaStyle(
    val brush: Brush,
    val alpha: Float = 1.0f, // @FloatRange(from = 0.0, to = 1.0)
    val colorFilter: ColorFilter? = null,
    val blendMode: BlendMode = DrawScope.DefaultBlendMode,
)

fun DrawScope.fillRectangle(
    leftTop: Offset,
    rightBottom: Offset,
    areaStyle: AreaStyle
) {
    drawRect(
        brush = areaStyle.brush,
        topLeft = leftTop,
        size = (rightBottom - leftTop).run { Size(x, y) },
        alpha = areaStyle.alpha,
        style = Fill,
        colorFilter = areaStyle.colorFilter,
        blendMode = areaStyle.blendMode
    )
}